package com.manger.common.tcp.client;

import com.manger.common.tcp.client.handler.TcpClientDataHandler;
import com.manger.common.tcp.client.handler.TcpClientHeartBeatHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.bytes.ByteArrayDecoder;
import io.netty.handler.codec.bytes.ByteArrayEncoder;
import io.netty.handler.timeout.IdleStateHandler;

import java.util.concurrent.TimeUnit;

public class TcpClientChannel extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ch.pipeline().addLast("idle",new IdleStateHandler(7, 5, 0,
                TimeUnit.SECONDS));
        ch.pipeline().addLast(
                new ByteArrayDecoder(),
                new ByteArrayEncoder()
        );
        ch.pipeline().addLast("handle",new TcpClientDataHandler());

        ch.pipeline().addLast("myIdle",new TcpClientHeartBeatHandler());

    }
}
